Skip to content

Internal: Remove _ for array lengths#467

Merged
chelsea0x3b merged 2 commits into
mainfrom
publish-fix
Oct 27, 2025
Merged

Internal: Remove _ for array lengths#467
chelsea0x3b merged 2 commits into
mainfrom
publish-fix

Conversation

@chelsea0x3b

Copy link
Copy Markdown
Owner

This is for some reason an error when running cargo publish but not cargo clippy? 🤔

@chelsea0x3b chelsea0x3b changed the title Remove _ for array lengths Internal: Remove _ for array lengths Oct 27, 2025

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly fixes a build issue with cargo publish by replacing inferred-length array initializers ([0; _]) with an explicit length ([0; 16]). This is a good fix. However, to further improve the code's robustness and make it more idiomatic, I've suggested using ..Default::default() for struct initialization. This approach is more resilient to future changes in the underlying C API struct definitions, as it automatically handles the initialization of remaining fields, including conditionally compiled ones. This avoids hardcoding the array length and makes the code cleaner and safer.

Comment thread src/driver/result.rs
Comment on lines 1163 to +1164
flags: 0,
reserved: [0; _],
reserved: [0; 16],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While hardcoding 16 fixes the build issue, it makes the code brittle. If the reserved field in CUDA_EXTERNAL_MEMORY_HANDLE_DESC ever changes size in a future CUDA version, this code will be incorrect. A more robust and idiomatic way to initialize the remaining fields is to use ..Default::default(). This will correctly zero-initialize flags and reserved and will adapt to future changes in the struct definition.

Suggested change
flags: 0,
reserved: [0; _],
reserved: [0; 16],
..Default::default()

Comment thread src/driver/result.rs
Comment on lines 1229 to +1230
flags: 0,
reserved: [0; _],
reserved: [0; 16],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to the previous change, hardcoding 16 here is brittle. Using ..Default::default() is a more robust and idiomatic way to initialize the remaining fields of the struct to their default (zero) values.

Suggested change
flags: 0,
reserved: [0; _],
reserved: [0; 16],
..Default::default()

Comment thread src/runtime/result.rs
Comment on lines 945 to +947
flags: 0,
#[cfg(feature = "cuda-13000")]
reserved: [0; _],
reserved: [0; 16],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using ..Default::default() is more robust and idiomatic than manually zeroing fields. It will correctly initialize flags and, when the cuda-13000 feature is enabled, the reserved field. This also makes the code consistent with the import_external_memory_opaque_win32 function in this file.

Suggested change
flags: 0,
#[cfg(feature = "cuda-13000")]
reserved: [0; _],
reserved: [0; 16],
..Default::default()

Comment thread src/runtime/result.rs
Comment on lines 1014 to +1016
flags: 0,
#[cfg(feature = "cuda-13000")]
reserved: [0; _],
reserved: [0; 16],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to the other changes, using ..Default::default() here is more robust. It will correctly zero-initialize flags and, when the cuda-13000 feature is enabled, the reserved field, adapting to any future changes in the struct definition.

Suggested change
flags: 0,
#[cfg(feature = "cuda-13000")]
reserved: [0; _],
reserved: [0; 16],
..Default::default()

@chelsea0x3b chelsea0x3b merged commit 4ddc9e2 into main Oct 27, 2025
18 checks passed
@chelsea0x3b chelsea0x3b deleted the publish-fix branch October 27, 2025 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant